<template>
    <div class="enterprise-info-container">
        <div class="enterprise-info-text" :style="{'marginBottom': '30px'}">机构信息:</div>
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="机构编号">
                <el-input :disabled="true" v-model="form.id"></el-input>
            </el-form-item>
            <el-form-item label="公司名称">
                <el-input :disabled="disableForm" v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="审核状态">
                <el-input :disabled="true" v-model="auth_text"></el-input>
            </el-form-item>
            <el-form-item label="公司概况">
                <el-input
                    :disabled="disableForm"
                    maxlength="255"
                    type="textarea"
                    :autosize="{ minRows: 4, maxRows: 4}"
                    v-model="form.detail">
                </el-input>
            </el-form-item>
            <el-form-item label="联系方式">
                <el-input
                    :disabled="disableForm"
                    maxlength="255"
                    type="textarea"
                    :autosize="{ minRows: 4, maxRows: 4}"
                    v-model="form.link">
                </el-input>
            </el-form-item>
            <el-button v-if="form.auth==1 && role=='admin'" type="success" :style="{'marginTop': '20px'}" @click="handleAuth">
                认证通过
            </el-button>
        </el-form>
    </div>
</template>

<script>
    import {ROLE_KEY} from "../../constants";
    import {authEnterprise, getOneEnterprise} from "../../api/enterprise";

    export default {
        name: "index",
        data() {
            return {
                role: '',
                bid: 0,
                auth_text: '未审核',
                form: {
                    id: '',
                    name: '',
                    detail: '',
                    link: '',
                    auth: 0
                },
                disableForm: true,
            }
        },
        methods: {
            handleAuth() {
                authEnterprise({id: this.bid}).then(res => {
                    window.location.reload()
                })
            }
        },
        mounted() {
            let bid = this.$route.query.id
            this.bid = bid
            this.role = localStorage.getItem(ROLE_KEY)
            getOneEnterprise({id: bid}).then(res => {
                this.form = res.data
                if(this.form.auth == 0) {
                    this.auth_text = '未认证'
                } else if(this.form.auth == 1) {
                    this.auth_text = '认证中'
                } else {
                    this.auth_text = '已认证'
                }
            })
        }
    }
</script>

<style lang="scss" scoped>
    .enterprise-info {
        &-container {
            margin: 30px;
            width: 50%;
        }

        &-text {
            font-size: 36px;
            line-height: 46px;
            font-weight: 600;
        }
    }

</style>
